package com.mingqijia.gassafety.authority.vcc.valueobject;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.mingqijia.gassafety.shared.enums.ManagerType;
import com.mingqijia.gassafety.shared.user.UserBackend;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.sql.Timestamp;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author Damon S.
 * @version v0.2
 * @date {YEAR}年{MONTH}月{DAY}日 {TIME}
 */
@Data
public class VccUserVO implements UserDetails, UserBackend {
    /** 唯一标识 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String openid;
    /** 所属组织ID */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String spId;
    /** 过期时间 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer expireTime;
    /** 开放平台标识 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String openAppId;
    /** 刷新令牌 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String refreshToken;
    /** 刷新令牌过期时间 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer refreshTokenExpiration;
    /** VCC 生效 令牌 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String token;
    /** VCC 生效 失效时间 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Long expireAt;
    /** 手机号 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String phone;
    /** vcc用户id */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String vccUserId;
    /** 用户名称 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String name;
    /** 用户名 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String username;
    /** 加密密码 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String password;
    /** 账号类型 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private ManagerType type;
    /** 所属组织 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<String> hierarchy;
    /** 部门 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<String> department;
    /** 所属角色 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<String> roleIds;
    /** 上次登录的企业ID */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String workingSpId;
    /** 最近一次登录时间 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Timestamp loginAt;
    /** 最后登出时间 */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Timestamp logoutAt;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String loginType;

    @Override
    @JsonIgnore
    public String getUserId() {
        return getOpenid();
    }

    @Override
    @JsonIgnore
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.emptyList();
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonLocked() {
        return isEnabled();
    }

    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isEnabled() {
        return true;
    }
}
